home *** CD-ROM | disk | FTP | other *** search
/ MacHome 1999 Game / Image.bin / Role Playing and Strategy / Starbound II.hqx / Starbound II / AI agents / Gypsum.rsrc / ss$t_138 < prev    next >
Encoding:
Text File  |  1998-05-14  |  1.1 KB  |  45 lines

  1. situation planetary_squad
  2. vars
  3.    me : squad;
  4.    my_race : integer;
  5.    my_location : integer;
  6.    target : integer;
  7.    focus : squad;
  8.    loc : integer;
  9.    success : boolean;
  10.  
  11. begin
  12.    // Find the nearest enemy squad and move toward it
  13.    me := This_squad();
  14.    my_race := Squad_race(me);
  15.    my_location := Squad_hex(me);
  16.    target := -1;
  17.    focus := First_squad(-1);
  18.    while (focus <> nil) do
  19.       begin
  20.          if (Squad_race(focus) <> my_race) then
  21.             begin
  22.                loc := Squad_hex(focus);
  23.                if (target = -1) then
  24.                   begin
  25.                      target := loc;
  26.                   end;
  27.                else
  28.                   begin
  29.                      if (Planet_distance(my_location, loc) <
  30.                          Planet_distance(my_location, target)) then
  31.                         target := loc;
  32.                   end;
  33.             end;
  34.          focus := Next_squad(focus, -1);
  35.       end;
  36.    if (target = -1) then
  37.       success := Move_squad(my_location);
  38.    else
  39.       begin
  40.          success := Move_squad(target);
  41.          if (not success) then
  42.             success := Move_squad(my_location);
  43.       end;
  44. end;
  45.